#ifndef GLUTES_INTERNAL_H
#define GLUTES_INTERNAL_H

#define  MINIGLUT_MAX_MENUS         3
#define  MINIGLUT_DEBUG             1

#define _INT2FIXED(_x_) (GLfixed)((_x_) << 16)
#define _FIXED2INT(_x_) (int)((_x_) >> 16)
#define _FLOAT2FIXED(_x_) (GLfixed)((_x_) *  (float)(1 << 16) + 0.5f)
#define _FIXED2FLOAT(_x_) ((float)(_x_) / (float)(1 << 16))

/* 
 * We just want support wince platform here
 */
#include <windows.h>
#include <windowsx.h>

#define strdup   _strdup
#endif

/*
 * Those files should be available on every platform.
 */
#include <GLES2/gl2.h>
#include <EGL/egl.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <stdarg.h>


#ifndef TRUE
#define   TRUE 1
#endif

#ifndef FALSE
#define   FALSE 0
#endif


/* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */

/*
 * Miniglut callbacks type definitions
 */
typedef void (* MGCBDisplay       )( void );
typedef void (* MGCBReshape       )( int, int );
typedef void (* MGCBVisibility    )( int );
typedef void (* MGCBKeyboard      )( unsigned char, int, int );
typedef void (* MGCBSpecial       )( int, int, int );
typedef void (* MGCBMouse         )( int, int, int, int );
typedef void (* MGCBMouseWheel    )( int, int, int, int );
typedef void (* MGCBMotion        )( int, int );
typedef void (* MGCBPassive       )( int, int );
typedef void (* MGCBEntry         )( int );
typedef void (* MGCBWindowStatus  )( int );
typedef void (* MGCBSelect        )( int, int, int );
typedef void (* MGCBJoystick      )( unsigned int, int, int, int );
typedef void (* MGCBKeyboardUp    )( unsigned char, int, int );
typedef void (* MGCBSpecialUp     )( int, int, int );
typedef void (* MGCBOverlayDisplay)( void );
typedef void (* MGCBSpaceMotion   )( int, int, int );
typedef void (* MGCBSpaceRotation )( int, int, int );
typedef void (* MGCBSpaceButton   )( int, int );
typedef void (* MGCBDials         )( int, int );
typedef void (* MGCBButtonBox     )( int, int );
typedef void (* MGCBTabletMotion  )( int, int );
typedef void (* MGCBTabletButton  )( int, int, int, int );
typedef void (* MGCBDestroy       )( void );

/*
 * The global callbacks type definitions
 */
typedef void (* MGCBIdle          )( void );
typedef void (* MGCBTimer         )( int );
typedef void (* MGCBMenuState     )( int );
typedef void (* MGCBMenuStatus    )( int, int, int );

/*
 * The callback used when creating/using menus
 */
typedef void (* MGCBMenu          )( int );

/*
 * A list structure
 */
typedef struct tagSMG_List SMG_List;
struct tagSMG_List
{
    void *First;
    void *Last;
};

/*
 * A list node structure
 */
typedef struct tagSMG_Node SMG_Node;
struct tagSMG_Node
{
    void *Next;
    void *Prev;
};

/*
 * A helper structure holding two ints and a boolean
 */
typedef struct tagSMG_XYUse SMG_XYUse;
struct tagSMG_XYUse
{
    GLint           X, Y;               /* The two integers...               */
    GLboolean       Use;                /* ...and a single boolean.          */
};

/*
 * A helper structure holding a timeval and a boolean
 */
typedef struct tagSMG_Time SMG_Time;
struct tagSMG_Time
{
    DWORD Value;
    GLboolean       Set;
};

/*
 * An enumeration containing the state of the GLUT execution:
 * initializing, running, or stopping
 */
typedef enum
{
  GLUT_EXEC_STATE_INIT,
  GLUT_EXEC_STATE_RUNNING,
  GLUT_EXEC_STATE_STOP
} mgExecutionState ;

/*
 * This structure holds different freeglut settings
 */
typedef struct tagSMG_State SMG_State;
struct tagSMG_State
{
    SMG_XYUse        Position;             /* The default windows' position  */
    SMG_XYUse        Size;                 /* The default windows' size      */
    unsigned int     DisplayMode;          /* Display mode for new windows   */

    GLboolean        Initialised;          /* freeglut has been initialised  */

    GLboolean        ForceDirectContext;   /* Force direct rendering?        */
    GLboolean        TryDirectContext;     /* What about giving a try to?    */

    GLboolean        ForceIconic;          /* New top windows are iconified  */
    GLboolean        UseCurrentContext;    /* New windows share with current */

    GLboolean        GLDebugSwitch;        /* OpenGL state debugging switch  */

    GLboolean        IgnoreKeyRepeat;      /* Whether to ignore key repeat.  */
    int              Modifiers;            /* Current ALT/SHIFT/CTRL state   */

    GLuint           FPSInterval;          /* Interval between FPS printfs   */
    GLuint           SwapCount;            /* Count of glutSwapBuffer calls  */
    GLuint           SwapTime;             /* Time of last SwapBuffers       */

    SMG_Time         Time;                 /* Time that glutInit was called  */
    SMG_List         Timers;               /* The freeglut timer hooks       */
    SMG_List         FreeTimers;           /* The unused timer hooks         */

    MGCBIdle         IdleCallback;         /* The global idle callback       */

    int              ActiveMenus;          /* Num. of currently active menus */
    MGCBMenuState    MenuStateCallback;    /* Menu callbacks are global      */
    MGCBMenuStatus   MenuStatusCallback;

    SMG_XYUse        GameModeSize;         /* Game mode screen's dimensions  */
    int              GameModeDepth;        /* The pixel depth for game mode  */
    int              GameModeRefresh;      /* The refresh rate for game mode */

    int              ActionOnWindowClose; /* Action when user closes window  */

    mgExecutionState ExecState;           /* Used for GLUT termination       */
    char            *ProgramName;         /* Name of the invoking program    */
};











#endif GLUTES_INTERNAL_H